<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
/*ini_set("memory_limit", "200M");
  mysql_connect("host=localhost dbname=hero  user=root  password=root")
   or die('Could not connect:'.mysql_last_error());
*/
$db_name="hero";  
 
$table_name="hero";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());
$stime =  date("Y-m-d",strtotime("-61 day"));
$etime =  date("Y-m-d",strtotime("-1 day"));
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `hero` WHERE date BETWEEN '$stime' AND '$etime'");

while($everylogdate = mysql_fetch_array($logdate))
{
      //游戏总注册人数
    $loginPersonNum_query = mysql_query("SELECT count(DISTINCT deviceid) FROM hero ");

    $loginPersonNum = mysql_fetch_array($loginPersonNum_query);

     //日均活跃人数 
    $activePesonrNum_query = mysql_query("select(SELECT count(DISTINCT deviceid)  FROM hero)/(SELECT count( DISTINCT date )FROM hero)");
    $activePesonrNum = mysql_fetch_array($activePesonrNum_query);

     //日均活跃人次 activePesonrTime 一个人可能多次
    $activePesonrTime_query = mysql_query("select (SELECT count(deviceid)  FROM hero)/(SELECT count( DISTINCT date )FROM hero)");
    $activePesonrTime = mysql_fetch_array($activePesonrTime_query);

    //日均人均打开次数  //DISTINCT deviceid
    $totalDailyLoginTimes_query = mysql_query("SELECT avg(todayOpenTimes)  FROM hero");
    $totalDailyLoginTimes = mysql_fetch_array($totalDailyLoginTimes_query);

    //日均游戏时间
    $totalDayTotalTime_query = mysql_query("SELECT avg(todayGameTime)  FROM hero");
    $totalDayTotalTime = mysql_fetch_array($totalDayTotalTime_query);

     //日均金钱获得 //字段缺失
    $totalDayGetMoney_query = mysql_query("SELECT avg(IAPMoney) FROM hero");
    $totalDayGetMoney = mysql_fetch_array($totalDayGetMoney_query);

    //日均IAP金钱获得
    $totalDayGetIAPMoney_query = mysql_query("select (SELECT sum(IAPMoney) FROM hero  where  date ='$everylogdate[date]')/(SELECT count(DISTINCT deviceid)  FROM hero  where date ='$everylogdate[date]' and   date <> RegisterDate)");
    $totalDayGetIAPMoney = mysql_fetch_array($totalDayGetIAPMoney_query);

    //日均充值  //字段缺失

    //$totalDayRecharge_query = mysql_query("SELECT avg(DailyGDGetFromGame) FROM hero ");
    //$totalDayRecharge = mysql_fetch_array($totalDayRecharge_query);
    
    //日均消费totalDayUsedMoney

    $totalDayUsedMoney_query = mysql_query("SELECT avg(resetSkillCost + buyEquipCost + shopRefreshCost + upgradeCost + hireHeroCost)  FROM  hero ");
    $totalDayUsedMoney = mysql_fetch_array($totalDayUsedMoney_query);
     
    //日均注册人数
    $dayLoginPersonNum_query = mysql_query("select(SELECT count(DISTINCT deviceid) FROM hero )/(SELECT count( DISTINCT date )FROM hero )");

    $dayLoginPersonNum = mysql_fetch_array($dayLoginPersonNum_query);

    //totalDayNewusers 每日新注册 DISTINCT
    $totalDayNewusers_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  hero  where RegisterDate = '$everylogdate[date]'");
    $totalDayNewusers = mysql_fetch_array($totalDayNewusers_query);

    //DayActivePesonrNum  每日活跃人数  //  日均DailyLoginTimes 活跃人数 今日的
    $dayActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM hero  where date ='$everylogdate[date]' and   date <> RegisterDate");
    $dayActivePesonrNum = mysql_fetch_array($dayActivePesonrNum_query);


    //dayActivePesonrTime 每日活跃人次
    $dayActivePesonrTime_query = mysql_query("SELECT sum( todayOpenTimes ) FROM hero WHERE  date ='$everylogdate[date]' and   date <> RegisterDate ");
    $dayActivePesonrTime = mysql_fetch_array($dayActivePesonrTime_query);

    //weekOneLandPesonrNum 过去7日内1次登录用户数
     $weekOneLandPesonrNum_query = mysql_query(" SELECT DISTINCT deviceid, date
        FROM hero
        WHERE date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >0
        ");
     $weekOneLandPesonrNum = mysql_num_rows($weekOneLandPesonrNum_query);

     //weekActivePesonrNum   过去7日内2次登录用户数 每周活跃人数  SELECT * FROM hero   where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )
    $weekActivePesonrNum_query = mysql_query("  SELECT DISTINCT deviceid, date
        FROM hero
        WHERE date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1
        ");
    //$weekActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  hero  where date_add(date,interval 2 day)   and DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )  and  JailBreak = '0'");
    $weekActivePesonrNum = mysql_num_rows($weekActivePesonrNum_query);

    //weekLoyalPesonrNum  过去7日内3次登录用户数 每周忠诚用户人数
    $weekLoyalPesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM hero
        WHERE date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >2
        ");
   $weekLoyalPesonrNum = mysql_num_rows($weekLoyalPesonrNum_query);


    //weekCorePesonrNum   过去7日内4次登录用户数 每周核心用户人数
    $weekCorePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM hero
        WHERE date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >3
        ");
    $weekCorePesonrNum = mysql_num_rows($weekCorePesonrNum_query);

    // 挂网等雇佣用户数 //字段缺失
    //$hirePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM  hero  where  date ='$everylogdate[date]'  and  JailBreak = '0'");
    //$hirePesonrNum = mysql_fetch_array($hirePesonrNum_query);

    //  今日均人均游戏时间
    $dayTotalTime_query = mysql_query("select (SELECT sum(todayGameTime)  FROM hero  where  date ='$everylogdate[date]')/(SELECT count(DISTINCT deviceid)  FROM hero  where date ='$everylogdate[date]' and   date <> RegisterDate)");
    $dayTotalTime = mysql_fetch_array($dayTotalTime_query);

    //  今日均消费金钱 DayUsedMoney 
    $dayUsedMoney_query = mysql_query("select (SELECT sum(resetSkillCost + buyEquipCost + shopRefreshCost + upgradeCost + hireHeroCost)  FROM  hero   where date ='$everylogdate[date]')/('$dayActivePesonrNum[0]')");
    $dayUsedMoney = mysql_fetch_array($dayUsedMoney_query);

        //weekPayPesonrNum 周付费用户数 SELECT count( DISTINCT deviceid )   
    $weekPayPesonrNum_query = mysql_query("SELECT DISTINCT deviceid
        FROM `hero`
        WHERE cents099 >0
        AND date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        UNION
        SELECT DISTINCT deviceid
        FROM `hero`
        WHERE Cents1999 >0
        AND date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        UNION
        SELECT DISTINCT deviceid
        FROM `hero`
        WHERE Cents499 >0
        AND date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        UNION
        SELECT DISTINCT deviceid
        FROM `hero`
        WHERE Cents4999 >0
        AND date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        UNION
        SELECT DISTINCT deviceid
        FROM `hero`
        WHERE Cents9999 >0
        AND date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' ");
    $weekPayPesonrNum = mysql_num_rows($weekPayPesonrNum_query);
    //dayIAPGetMoney  今日人均 IAP 获得金钱
    $dayIAPGetMoney_query = mysql_query("select (SELECT sum(IAPMoney)  FROM  hero  where  date ='$everylogdate[date]' )/(SELECT count(deviceid)  FROM  hero  where  date ='$everylogdate[date]')");
    $dayIAPGetMoney = mysql_fetch_array($dayIAPGetMoney_query);
    //dayNowMoney  今日人均现有金钱
    $dayNowMoney_query = mysql_query("select (SELECT sum(allGetMoney)  FROM  hero  where  date ='$everylogdate[date]' )/(SELECT count(deviceid)  FROM  hero  where  date ='$everylogdate[date]' )");
    $dayNowMoney = mysql_fetch_array($dayNowMoney_query);
       //dayRechargeNum  今日人均充值笔数
    $dayRechargeNum_query = mysql_query("select '$paytimes[0]'/'$PayPesonrNum'");
    $dayRechargeNum = mysql_fetch_array($dayRechargeNum_query);

    //weekPayARPU 周付费用户ARPU值 =周付费总额/周付费人数
    $weekPayARPU_query = mysql_query("SELECT (
        SELECT sum(cents099*99 +Cents1999 *1999 + Cents499 *499 + Cents4999 *4999 + Cents9999*9999)
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]') / ('$weekPayPesonrNum' )");

    $weekPayARPU = mysql_fetch_array($weekPayARPU_query); 
  //weekActiveARPU 周活跃用户ARPU值
    $weekActiveARPU_query = mysql_query("SELECT (
        SELECT sum(cents099*99 +Cents1999 *1999 + Cents499 *499 + Cents4999 *4999 + Cents9999*9999)
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]') / ($weekActivePesonrNum) ");
   $weekActiveARPU = mysql_fetch_array($weekActiveARPU_query);
       //weekLogARPU 周登陆用户ARPU值  = 周付费用户/周登陆人数(活跃用户+新用户)  
   $weekLogARPU_query = mysql_query("SELECT (
        SELECT sum(cents099*99 +Cents1999 *1999 + Cents499 *499 + Cents4999 *4999 + Cents9999*9999)
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]') / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' ) ");
      $weekLogARPU = mysql_fetch_array($weekLogARPU_query);

     //weekPayRate  周活跃用户付费率 周付费用户数除以周活跃人数
    //$weekPayRate_query = mysql_query("select '$weekPayPesonrNum[0]'/'$weekActivePesonrNum[0]'");
    $weekPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum'/  '$weekActivePesonrNum' *100,2), '%' ) ");
    $weekPayRate = mysql_fetch_array($weekPayRate_query);
    //weekLogPayRate周登陆用户付费率 周付费用户数除以周登陆人数
    $weekLogPayRate_query = mysql_query("SELECT concat(round( '$weekPayPesonrNum'/  '$weekOneLandPesonrNum' *100,2), '%' ) ");
    $weekLogPayRate = mysql_fetch_array($weekLogPayRate_query);

     //weekWastageRate  周活跃用户流失率 上周活跃用户在本周没有登陆过游戏的用户数，除以上周的活跃人数。   
     /* 
      SELECT count(deviceid )FROM dinocap2hd WHERE 
YEARWEEK( date_format( whatday, '%Y-%m-%d' ) ) = YEARWEEK('2012-04-10' ) AND dayPlayTime >0 AND isjailbreak = '0'*/
      
    // $weekWastageRate_query = mysql_query("select (select sum(deviceid) from dinocap2hd where (SELECT distinct deviceid FROM dinocap2hd   WHERE YEARWEEK(date_format(whatday,'%Y-%m-%d')) = YEARWEEK('$everylogdate[whatday]')-1 and dayIapMoney >0 and dayPlayTime >2) not in (SELECT  distinct deviceid FROM dinocap2hd WHERE DATE_SUB( whatday, INTERVAL 7 DAY ) <= date( '$everylogdate[whatday]' )))/(SELECT count(distinct deviceid) FROM dinocap2hd   WHERE YEARWEEK(date_format(whatday,'%Y-%m-%d')) = YEARWEEK('$everylogdate[whatday]')-1 and dayIapMoney >0 and dayPlayTime >2)");
    $weekWastageRate_query = mysql_query("SELECT concat( round((
        SELECT (
        SELECT count( a.deviceid )
        FROM weekActive a
        WHERE a.date = date_sub('$everylogdate[date]',interval 7 day)  
        AND a.deviceid NOT
        IN (
        SELECT DISTINCT deviceid
        FROM hero
        WHERE  date
        BETWEEN DATE_SUB('$everylogdate[whatday]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekActive
        WHERE date = date_sub('$everylogdate[date]',interval 7 day))
        ) *100,2), '%'
        ) ");
     $weekWastageRate = mysql_fetch_array($weekWastageRate_query);

     //weekPayWastageRate  周付费用户流失率 上周有付费行为而本周7天未登陆的用户数除以上周的付费用户数    //sql查询慢,需要优化
   //SELECT count(id)  FROM  dinocap2hd WHERE DATE_SUB( whatday, INTERVAL 7 DAY ) <= date( '$everylogdate[whatday]' ) -1 and dayIapMoney >0 and whatday = '2012-03-28' where 
    // $weekPayWastageRate_query = mysql_query("select (select count(deviceid) FROM  dinocap2hd where (SELECT distinct deviceid FROM dinocap2hd   WHERE YEARWEEK(date_format(whatday,'%Y-%m-%d')) = YEARWEEK('$everylogdate[whatday]')-1 and dayIapMoney >0) not in (SELECT  distinct deviceid FROM dinocap2hd WHERE DATE_SUB( whatday, INTERVAL 7 DAY ) <= date( '$everylogdate[whatday]' )) and whatday = '$everylogdate[whatday]')/(SELECT distinct deviceid FROM dinocap2hd   WHERE YEARWEEK(date_format(whatday,'%Y-%m-%d')) = YEARWEEK('$everylogdate[whatday]')-1 and dayIapMoney >0 and whatday = '$everylogdate[whatday]')");
      $weekPayWastageRate_query = mysql_query("SELECT concat( round((
        SELECT (
        SELECT count( a.deviceid )
        FROM weekPay a
        WHERE a.date = date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND a.deviceid NOT
        IN (

        SELECT DISTINCT deviceid
        FROM hero
        WHERE  date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) / (
        SELECT count( 1 )
        FROM weekPay
        WHERE date =  date_sub('$everylogdate[date]',interval 7 day) )
        ) *100,2), '%'
        ) ");
     $weekPayWastageRate = mysql_fetch_array($weekPayWastageRate_query);
   /* //avgDayMoney  今日人均获得金钱 字段缺失
    $avgDayMoney_query = mysql_query("select (SELECT sum(DailyGDGetFromGame)  FROM  hero  where  date ='$everylogdate[date]')/(SELECT count(deviceid)  FROM  hero  where  date ='$everylogdate[date]' )");
    $avgDayMoney = mysql_fetch_array($avgDayMoney_query);
     
      //weekWastageRate  周活跃用户流失率 上周活跃用户在本周没有登陆过游戏的用户数，除以上周的活跃人数。
      $weekWastageRate_query = mysql_query("SELECT (SELECT count( DISTINCT deviceid )FROM `hero` WHERE (SELECT count( DISTINCT deviceid ) FROM hero WHERE DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) -1 AND DailyGDGetFromGame >0 AND DailyLoginTimes >2 ) NOT IN (SELECT DISTINCT deviceid FROM hero WHERE YEARWEEK( date_format( date, '%Y-%m-%d' ) ) = YEARWEEK('$everylogdate[date]' ))) / (SELECT count( DISTINCT deviceid )FROM hero WHERE YEARWEEK( date_format( date, '%Y-%m-%d' ) ) = YEARWEEK('$everylogdate[date]' ) -1 AND DailyGDGetFromGame >0 AND DailyLoginTimes >2  ) ");
     $weekWastageRate = mysql_fetch_array($weekWastageRate_query); 
         //weekPayRate  周活跃用户付费率 周付费用户数除以周活跃人数
     $weekPayRate_query = mysql_query("select (select count(distinct deviceid) from hero where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) and DailyGDGetFromGame > 0 )/(SELECT count(distinct deviceid) FROM hero   WHERE YEARWEEK(date_format(date,'%Y-%m-%d')) = YEARWEEK('$everylogdate[date]')-1 and DailyGDGetFromGame >0 and DailyLoginTimes >2 )");
    $weekPayRate = mysql_fetch_array($weekPayRate_query);
    //weekLogPayRate周登陆用户付费率 周付费用户数除以周登陆人数
    $weekLogPayRate_query = mysql_query("select (select count(distinct deviceid) from hero where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) and DailyGDGetFromGame > 0 )/(select count(distinct deviceid) from hero where DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) )");
    $weekLogPayRate = mysql_fetch_array($weekLogPayRate_query);
       //weekPayWastageRate  周付费用户流失率 上周有付费行为而本周7天未登陆的用户数除以上周的付费用户数  
    $weekPayWastageRate_query = mysql_query("SELECT (SELECT count( DISTINCT deviceid )FROM `hero` WHERE (SELECT count( DISTINCT deviceid ) FROM hero WHERE DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) -1 AND DailyGDGetFromGame >0 ) NOT IN (SELECT DISTINCT deviceid FROM hero WHERE DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' )) ) / (SELECT count( DISTINCT deviceid ) FROM hero WHERE DATE_SUB( date, INTERVAL 7 DAY ) <= date( '$everylogdate[date]' ) -1 AND DailyGDGetFromGame >0  ) ");
     $weekPayWastageRate = mysql_fetch_array($weekPayWastageRate_query);

    //今日TC兑换次数 
   // $DailyTCTimes_query = mysql_query("SELECT sum(DailyTCTimes)  FROM  hero  where date = '$everylogdate[date]'");
   // $DailyTCTimes = mysql_fetch_array($DailyTCTimes_query);

    //今日TC兑换金钱消耗量
    //$DailyTCLost_query = mysql_query("SELECT sum(DailyTCLost)  FROM  hero  where date = '$everylogdate[date]'");
   // $DailyTCLost = mysql_fetch_array($DailyTCLost_query);
   */
          //周付费用户人均充值笔数
     $weekPayPesonrTime_query = mysql_query("SELECT '$WeekPayRechargeNum[0]'/'$weekPayPesonrNum'");
     $weekPayPesonrTime = mysql_fetch_array($weekPayPesonrTime_query);

    //最后退出 10界面 人数统计 Lastloginscreen10Num
    $Lastloginscreen10Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 10  and date ='$everylogdate[date]'");
    $Lastloginscreen10Num = mysql_fetch_array($Lastloginscreen10Num_query);

        //最后退出 21界面 人数统计 Lastloginscreen21Num
    $Lastloginscreen21Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 21  and date ='$everylogdate[date]'");
    $Lastloginscreen21Num = mysql_fetch_array($Lastloginscreen21Num_query);

        //最后退出 22界面 人数统计 Lastloginscreen22Num
    $Lastloginscreen22Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 22  and date ='$everylogdate[date]'");
    $Lastloginscreen22Num = mysql_fetch_array($Lastloginscreen22Num_query);
        //最后退出 23界面 人数统计 Lastloginscreen23Num
    $Lastloginscreen23Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 23  and date ='$everylogdate[date]'");
    $Lastloginscreen23Num = mysql_fetch_array($Lastloginscreen23Num_query);
        //最后退出 24界面 人数统计 Lastloginscreen24Num
    $Lastloginscreen24m_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 24  and date ='$everylogdate[date]'");
    $Lastloginscreen24Num = mysql_fetch_array($Lastloginscreen24m_query);
        //最后退出 31界面 人数统计 Lastloginscreen31Num
    $Lastloginscreen31Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 31  and date ='$everylogdate[date]'");
    $Lastloginscreen31Num = mysql_fetch_array($Lastloginscreen31Num_query);
        //最后退出 41界面 人数统计 Lastloginscreen41Num
    $Lastloginscreen41Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 41  and date ='$everylogdate[date]'");
    $Lastloginscreen41Num = mysql_fetch_array($Lastloginscreen41Num_query);
        //最后退出 42界面 人数统计 Lastloginscreen42Num
    $Lastloginscreen42Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 42  and date ='$everylogdate[date]'");
    $Lastloginscreen42Num = mysql_fetch_array($Lastloginscreen42Num_query);
        //最后退出 50界面 人数统计 Lastloginscreen50Num
    $Lastloginscreen50Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 50  and date ='$everylogdate[date]'");
    $Lastloginscreen50Num = mysql_fetch_array($Lastloginscreen50Num_query);
        //最后退出 60界面 人数统计 Lastloginscreen60Num
    $Lastloginscreen60Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 60  and date ='$everylogdate[date]'");
    $Lastloginscreen60Num = mysql_fetch_array($Lastloginscreen60Num_query);
        //最后退出 71界面 人数统计 Lastloginscreen71Num
    $Lastloginscreen71Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 71  and date ='$everylogdate[date]'");
    $Lastloginscreen71Num = mysql_fetch_array($Lastloginscreen71Num_query);
        //最后退出 72界面 人数统计 Lastloginscreen72Num
    $Lastloginscreen72Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 72  and date ='$everylogdate[date]'");
    $Lastloginscreen72Num = mysql_fetch_array($Lastloginscreen72Num_query);
        //最后退出 73界面 人数统计 Lastloginscreen73Num
    $Lastloginscreen73Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 73  and date ='$everylogdate[date]'");
    $Lastloginscreen73Num = mysql_fetch_array($Lastloginscreen73Num_query);
        //最后退出 80界面 人数统计 Lastloginscreen80Num
    $Lastloginscreen80Num_query = mysql_query("SELECT count(distinct deviceid) FROM hero where  exitWhichBattleGround = 80  and date ='$everylogdate[date]'");
    $Lastloginscreen80Num = mysql_fetch_array($Lastloginscreen80Num_query);
 

    // p1等级分布 (1,2,....)
    $date = array('1' => array($p1date1Count, $date1), array($p1date2Count, $date2), array($p1date3Count, $date3), array($p1date4Count, $date4), array($p1date5Count, $date5), array($p1date6Count, $date6), array($p1date7Count, $date7), array($p1date8Count, $date8), array($p1date9Count, $date9), array($p1date10Count, $date10), array($p1date11Count, $date11), array($p1date12Count, $date12), array($p1date13Count, $date13), array($p1date14Count, $date14), array($p1date15Count, $date15), array($p1date16Count, $date16), array($p1date17Count, $date17), array($p1date18Count, $date18), array($p1date19Count, $date19), array($p1date20Count, $date20), array($p1date21Count, $date21));
    // $date1[] = 
    /*$date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =1 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date1_a = mysql_fetch_array($date1_query);*/
    $date1_a =0;
    $date1 = $date1_a[0];
    $p1date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 1");
    $p1date1Count_a = mysql_fetch_array($p1date1Count_query);
    $p1date1Count = $p1date1Count_a[0];
    /*$date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =2 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date2_a = mysql_fetch_array($date2_query);*/
    $date2_a =0;
    $date2 = $date2_a[0];
    $p1date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 2");
    $p1date2Count_a = mysql_fetch_array($p1date2Count_query);
    $p1date2Count = $p1date2Count_a[0];
    /*$date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =3 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date3_a = mysql_fetch_array($date3_query);*/
    $date3_a =0;
    $date3 = $date3_a[0];
    $p1date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 3");
    $p1date3Count_a = mysql_fetch_array($p1date3Count_query);
    $p1date3Count = $p1date3Count_a[0];
    /*$date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =4 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date4_a = mysql_fetch_array($date4_query);*/
    $date4_a =0;
    $date4 = $date4_a[0];
    $p1date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 4");
    $p1date4Count_a = mysql_fetch_array($p1date4Count_query);
    $p1date4Count = $p1date4Count_a[0];
    /*$date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =5 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date5_a = mysql_fetch_array($date5_query);*/
    $date5_a =0;
    $date5 = $date5_a[0];
    $p1date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 5");
    $p1date5Count_a = mysql_fetch_array($p1date5Count_query);
    $p1date5Count = $p1date5Count_a[0];
    /*$date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =6 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date6_a = mysql_fetch_array($date6_query);*/
    $date6_a = 0;
    $date6 = $date6_a[0];
    $p1date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 6");
    $p1date6Count_a = mysql_fetch_array($p1date6Count_query);
    $p1date6Count = $p1date6Count_a[0];
    /*$date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =7 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date7_a = mysql_fetch_array($date7_query);*/
    $date7_a =0;
    $date7 = $date7_a[0];
    $p1date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 7");
    $p1date7Count_a = mysql_fetch_array($p1date7Count_query);
    $p1date7Count = $p1date7Count_a[0];
    /*$date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =8 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date8_a = mysql_fetch_array($date8_query);*/
    $date8_a =0;
    $date8 = $date8_a[0];
    $p1date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 8");
    $p1date8Count_a = mysql_fetch_array($p1date8Count_query);
    $p1date8Count = $p1date8Count_a[0];
    /*$date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =9 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date9_a = mysql_fetch_array($date9_query);*/
    $date9_a =0;
    $date9 = $date9_a[0];
    $p1date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 9");
    $p1date9Count_a = mysql_fetch_array($p1date9Count_query);
    $p1date9Count = $p1date9Count_a[0];
    /*$date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level =10 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date10_a = mysql_fetch_array($date10_query);*/
    $date10_a =0;
    $date10 = $date10_a[0];
    $p1date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level = 10");
    $p1date10Count_a = mysql_fetch_array($p1date10Count_query);
    $p1date10Count = $p1date10Count_a[0];
    /*$date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 11 and 15 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date11_a = mysql_fetch_array($date11_query);*/
    $date11_a =0;
    $date11 = $date11_a[0];
    $p1date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 11 and 15");
    $p1date11Count_a = mysql_fetch_array($p1date11Count_query);
    $p1date11Count = $p1date11Count_a[0];
    /*$date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 16 and 20 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date12_a = mysql_fetch_array($date12_query);*/
    $date12_a =0;
    $date12 = $date12_a[0];
    $p1date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 16 and 20");
    $p1date12Count_a = mysql_fetch_array($p1date12Count_query);
    $p1date12Count = $p1date12Count_a[0];
    /*$date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 21 and 25 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date13_a = mysql_fetch_array($date13_query);*/
    $date13_a =0;
    $date13 = $date13_a[0];
    $p1date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 21 and 25");
    $p1date13Count_a = mysql_fetch_array($p1date13Count_query);
    $p1date13Count = $p1date13Count_a[0];
    /*$date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 26 and 30 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date14_a = mysql_fetch_array($date14_query);*/
    $date14_a = 0;
    $date14 = $date14_a[0];
    $p1date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 26 and 30");
    $p1date14Count_a = mysql_fetch_array($p1date14Count_query);
    $p1date14Count = $p1date14Count_a[0];
    /*$date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 31 and 40 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date15_a = mysql_fetch_array($date15_query);*/
    $date15_a =0;
    $date15 = $date15_a[0];
    $p1date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 31 and 40");
    $p1date15Count_a = mysql_fetch_array($p1date15Count_query);
    $p1date15Count = $p1date15Count_a[0];
    /*$date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 41 and 50 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date16_a = mysql_fetch_array($date16_query);*/
    $date16_a = 0;
    $date16 = $date16_a[0];
    $p1date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 41 and 50");
    $p1date16Count_a = mysql_fetch_array($p1date16Count_query);
    $p1date16Count = $p1date16Count_a[0];
    /*$date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 51 and 60) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date17_a = mysql_fetch_array($date17_query);*/
    $date17_a =0;
    $date17 = $date17_a[0];
    $p1date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 51 and 60");
    $p1date17Count_a = mysql_fetch_array($p1date17Count_query);
    $p1date17Count = $p1date17Count_a[0];
    /*$date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 61 and 70 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date18_a = mysql_fetch_array($date18_query);*/
    $date18_a =0;
    $date18 = $date18_a[0];
    $p1date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 61 and 70");
    $p1date18Count_a = mysql_fetch_array($p1date18Count_query);
    $p1date18Count = $p1date18Count_a[0];
    /*$date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 71 and 80 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date19_a = mysql_fetch_array($date19_query);*/
    $date19_a =0;
    $date19 = $date19_a[0];
    $p1date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 71 and 80");
    $p1date19Count_a = mysql_fetch_array($p1date19Count_query);
    $p1date19Count = $p1date19Count_a[0];
    /*$date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 81 and 90 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date20_a = mysql_fetch_array($date20_query);*/
    $date20_a =0;
    $date20 = $date20_a[0];
    $p1date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 81 and 90");
    $p1date20Count_a = mysql_fetch_array($p1date20Count_query);
    $p1date20Count = $p1date20Count_a[0];
    /*$date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 91 and 100 ) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $date21_a = mysql_fetch_array($date21_query);*/
    $date21_a =0;
    $date21 = $date21_a[0];
    $p1date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_0_level between 91 and 100");
    $p1date21Count_a = mysql_fetch_array($p1date21Count_query);
    $p1date21Count = $p1date21Count_a[0];
    $heroData_0_level = array(json_encode($date));
    
      // p2等级分布
    $p2date = array('1' => array($p2date1Count, $p2date1), array($p2date2Count, $p2date2), array($p2date3Count, $p2date3), array($p2date4Count, $p2date4), array($p2date5Count, $p2date5), array($p2date6Count, $p2date6), array($p2date7Count, $p2date7), array($p2date8Count, $p2date8), array($p2date9Count, $p2date9), array($p2date10Count, $p2date10), array($p2date11Count, $p2date11), array($p2date12Count, $p2date12), array($p2date13Count, $p2date13), array($p2date14Count, $p2date14), array($p2date15Count, $p2date15), array($p2date16Count, $p2date16), array($p2date17Count, $p2date17), array($p2date18Count, $p2date18), array($p2date19Count, $p2date19), array($p2date20Count, $p2date20), array($p2date21Count, $p2date21));
    // $date1[] = 
    /*$p2date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 1) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date1_a = mysql_fetch_array($p2date1_query);*/
    $p2date1_a =0;
    $p2date1 = $p2date1_a[0];
    $p2date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 1");
    $p2date1Count_a = mysql_fetch_array($p2date1Count_query);
    $p2date1Count = $p2date1Count_a[0];
    /*$p2date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 2) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date2_a = mysql_fetch_array($p2date2_query);*/
    $p2date2_a =0;
    $p2date2 = $p2date2_a[0];
    $p2date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 2");
    $p2date2Count_a = mysql_fetch_array($p2date2Count_query);
    $p2date2Count = $p2date2Count_a[0];
    /*$p2date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 3) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date3_a = mysql_fetch_array($p2date3_query);*/
    $p2date3_a = 0;
    $p2date3 = $p2date3_a[0];
    $p2date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 3");
    $p2date3Count_a = mysql_fetch_array($p2date3Count_query);
    $p2date3Count = $p2date3Count_a[0];
    /*$p2date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 4) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date4_a = mysql_fetch_array($p2date4_query);*/
    $p2date4_a = 0;
    $p2date4 = $p2date4_a[0];
    $p2date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 4");
    $p2date4Count_a = mysql_fetch_array($p2date4Count_query);
    $p2date4Count = $p2date4Count_a[0];
    /*$p2date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 5) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date5_a = mysql_fetch_array($p2date5_query);*/
    $p2date5_a =0;
    $p2date5 = $p2date5_a[0];
    $p2date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 5");
    $p2date5Count_a = mysql_fetch_array($p2date5Count_query);
    $p2date5Count = $p2date5Count_a[0];
    /*$p2date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 6) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date6_a = mysql_fetch_array($p2date6_query);*/
    $p2date6_a =0;
    $p2date6 = $p2date6_a[0];
    $p2date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 6");
    $p2date6Count_a = mysql_fetch_array($p2date6Count_query);
    $p2date6Count = $p2date6Count_a[0];
    /*$p2date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 7) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date7_a = mysql_fetch_array($p2date7_query);*/
    $p2date7_a =0;
    $p2date7 = $p2date7_a[0];
    $p2date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 7");
    $p2date7Count_a = mysql_fetch_array($p2date7Count_query);
    $p2date7Count = $p2date7Count_a[0];
    /*$p2date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 8) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date8_a = mysql_fetch_array($p2date8_query);*/
    $p2date8_a =0;
    $p2date8 = $p2date8_a[0];
    $p2date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 8");
    $p2date8Count_a = mysql_fetch_array($p2date8Count_query);
    $p2date8Count = $p2date8Count_a[0];
    /*$p2date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 9) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date9_a = mysql_fetch_array($p2date9_query);*/
    $p2date9_a = 0;
    $p2date9 = $p2date9_a[0];
    $p2date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 9");
    $p2date9Count_a = mysql_fetch_array($p2date9Count_query);
    $p2date9Count = $p2date9Count_a[0];
    /*$p2date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  = 10) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date10_a = mysql_fetch_array($p2date10_query);*/
    $p2date10_a =0;
    $p2date10 = $p2date10_a[0];
    $p2date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level = 10");
    $p2date10Count_a = mysql_fetch_array($p2date10Count_query);
    $p2date10Count = $p2date10Count_a[0];
    /*$p2date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  11 and 15) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date11_a = mysql_fetch_array($p2date11_query);*/
    $p2date11_a = 0;
    $p2date11 = $p2date11_a[0];
    $p2date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 11 and 15");
    $p2date11Count_a = mysql_fetch_array($p2date11Count_query);
    $p2date11Count = $p2date11Count_a[0];
    /*$p2date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  16 and 20) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date12_a = mysql_fetch_array($p2date12_query);*/
    $p2date12_a =0;
    $p2date12 = $p2date12_a[0];
    $p2date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 16 and 20");
    $p2date12Count_a = mysql_fetch_array($p2date12Count_query);
    $p2date12Count = $p2date12Count_a[0];
    /*$p2date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  21 and 25) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date13_a = mysql_fetch_array($p2date13_query);*/
    $p2date13_a = 0;
    $p2date13 = $p2date13_a[0];
    $p2date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 21 and 25");
    $p2date13Count_a = mysql_fetch_array($p2date13Count_query);
    $p2date13Count = $p2date13Count_a[0];
    /*$p2date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  26 and 30) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date14_a = mysql_fetch_array($p2date14_query);*/
    $p2date14_a =0;
    $p2date14 = $p2date14_a[0];
    $p2date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 26 and 30");
    $p2date14Count_a = mysql_fetch_array($p2date14Count_query);
    $p2date14Count = $p2date14Count_a[0];
    /*$p2date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  31 and 40) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date15_a = mysql_fetch_array($p2date15_query);*/
    $p2date15_a =0;
    $p2date15 = $p2date15_a[0];
    $p2date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 31 and 40");
    $p2date15Count_a = mysql_fetch_array($p2date15Count_query);
    $p2date15Count = $p2date15Count_a[0];
    /*$p2date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  41 and 50) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date16_a = mysql_fetch_array($p2date16_query);*/
    $p2date16_a =0;
    $p2date16 = $p2date16_a[0];
    $p2date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 41 and 50");
    $p2date16Count_a = mysql_fetch_array($p2date16Count_query);
    $p2date16Count = $p2date16Count_a[0];
    /*$p2date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  51 and 60) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date17_a = mysql_fetch_array($p2date17_query);*/
    $p2date17_a =0;
    $p2date17 = $p2date17_a[0];
    $p2date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 51 and 60");
    $p2date17Count_a = mysql_fetch_array($p2date17Count_query);
    $p2date17Count = $p2date17Count_a[0];
    /*$p2date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  61 and 70) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date18_a = mysql_fetch_array($p2date18_query);*/
    $p2date18_a =0;
    $p2date18 = $p2date18_a[0];
    $p2date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 61 and 70");
    $p2date18Count_a = mysql_fetch_array($p2date18Count_query);
    $p2date18Count = $p2date18Count_a[0];
    /*$p2date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  71 and 80) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date19_a = mysql_fetch_array($p2date19_query);*/
    $p2date19_a = 0;
    $p2date19 = $p2date19_a[0];
    $p2date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 71 and 80");
    $p2date19Count_a = mysql_fetch_array($p2date19Count_query);
    $p2date19Count = $p2date19Count_a[0];
    /*$p2date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  81 and 90) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date20_a = mysql_fetch_array($p2date20_query);*/
    $p2date20_a =0;
    $p2date20 = $p2date20_a[0];
    $p2date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 81 and 90");
    $p2date20Count_a = mysql_fetch_array($p2date20Count_query);
    $p2date20Count = $p2date20Count_a[0];
    /*$p2date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level  between  91 and 100) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p2date21_a = mysql_fetch_array($p2date21_query);*/
    $p2date21_a =0;
    $p2date21 = $p2date21_a[0];
    $p2date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_1_level between 91 and 100");
    $p2date21Count_a = mysql_fetch_array($p2date21Count_query);
    $p2date21Count = $p2date21Count_a[0];
    $heroData_1_level = array(json_encode($p2date));
    // p3等级分布
    $p3date = array('1' => array($p3date1Count, $p3date1), array($p3date2Count, $p3date2), array($p3date3Count, $p3date3), array($p3date4Count, $p3date4), array($p3date5Count, $p3date5), array($p3date6Count, $p3date6), array($p3date7Count, $p3date7), array($p3date8Count, $p3date8), array($p3date9Count, $p3date9), array($p3date10Count, $p3date10), array($p3date11Count, $p3date11), array($p3date12Count, $p3date12), array($p3date13Count, $p3date13), array($p3date14Count, $p3date14), array($p3date15Count, $p3date15), array($p3date16Count, $p3date16), array($p3date17Count, $p3date17), array($p3date18Count, $p3date18), array($p3date19Count, $p3date19), array($p3date20Count, $p3date20), array($p3date21Count, $p3date21));
    // $date1[] = 
    /*$p3date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 1) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date1_a = mysql_fetch_array($p3date1_query);*/
    $p3date1_a =0;
    $p3date1 = $p3date1_a[0];

    $p3date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 1");
    $p3date1Count_a = mysql_fetch_array($p3date1Count_query);
    $p3date1Count = $p3date1Count_a[0];
    /*$p3date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 3) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date2_a = mysql_fetch_array($p3date2_query);*/
    $p3date2_a =0;
    $p3date2 = $p3date2_a[0];
    $p3date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 2");
    $p3date2Count_a = mysql_fetch_array($p3date2Count_query);
    $p3date2Count = $p3date2Count_a[0];
    /*$p3date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 4) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date3_a = mysql_fetch_array($p3date3_query);*/
    $p3date3_a =0;
    $p3date3 = $p3date3_a[0];
    $p3date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 3");
    $p3date3Count_a = mysql_fetch_array($p3date3Count_query);
    $p3date3Count = $p3date3Count_a[0];
    /*$p3date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 5) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date4_a = mysql_fetch_array($p3date4_query);*/
    $p3date4_a = 0;
    $p3date4 = $p3date4_a[0];
    $p3date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 4");
    $p3date4Count_a = mysql_fetch_array($p3date4Count_query);
    $p3date4Count = $p3date4Count_a[0];
    /*$p3date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 6) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date5_a = mysql_fetch_array($p3date5_query);*/
    $p3date5_a =0;
    $p3date5 = $p3date5_a[0];
    $p3date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 5");
    $p3date5Count_a = mysql_fetch_array($p3date5Count_query);
    $p3date5Count = $p3date5Count_a[0];
    /*$p3date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 7) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date6_a = mysql_fetch_array($p3date6_query);*/
    $p3date6_a =0;
    $p3date6 = $p3date6_a[0];
    $p3date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 6");
    $p3date6Count_a = mysql_fetch_array($p3date6Count_query);
    $p3date6Count = $p3date6Count_a[0];
    /*$p3date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 7) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date7_a = mysql_fetch_array($p3date7_query);*/
    $p3date7_a =0;
    $p3date7 = $p3date7_a[0];
    $p3date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 7");
    $p3date7Count_a = mysql_fetch_array($p3date7Count_query);
    $p3date7Count = $p3date7Count_a[0];
    /*$p3date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 8) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date8_a = mysql_fetch_array($p3date8_query);*/
    $p3date8_a =0;
    $p3date8 = $p3date8_a[0];
    $p3date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 8");
    $p3date8Count_a = mysql_fetch_array($p3date8Count_query);
    $p3date8Count = $p3date8Count_a[0];
    /*$p3date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 9) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date9_a = mysql_fetch_array($p3date9_query);*/
    $p3date9_a =0;
    $p3date9 = $p3date9_a[0];
    $p3date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 9");
    $p3date9Count_a = mysql_fetch_array($p3date9Count_query);
    $p3date9Count = $p3date9Count_a[0];
    /*$p3date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  = 10) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date10_a = mysql_fetch_array($p3date10_query);*/
    $p3date10_a =0;
    $p3date10 = $p3date10_a[0];
    $p3date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level = 10");
    $p3date10Count_a = mysql_fetch_array($p3date10Count_query);
    $p3date10Count = $p3date10Count_a[0];
    /*$p3date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 11 and 15) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date11_a = mysql_fetch_array($p3date11_query);*/
    $p3date11_a =0;
    $p3date11 = $p3date11_a[0];
    $p3date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 11 and 15");
    $p3date11Count_a = mysql_fetch_array($p3date11Count_query);
    $p3date11Count = $p3date11Count_a[0];
    /*$p3date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 16 and 20) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date12_a = mysql_fetch_array($p3date12_query);*/
    $p3date12_a =0;
    $p3date12 = $p3date12_a[0];
    $p3date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 16 and 20");
    $p3date12Count_a = mysql_fetch_array($p3date12Count_query);
    $p3date12Count = $p3date12Count_a[0];
    /*$p3date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 21 and 25) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date13_a = mysql_fetch_array($p3date13_query);*/
    $p3date13_a =0;
    $p3date13 = $p3date13_a[0];
    $p3date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 21 and 25");
    $p3date13Count_a = mysql_fetch_array($p3date13Count_query);
    $p3date13Count = $p3date13Count_a[0];
    /*$p3date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 26 and 30) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date14_a = mysql_fetch_array($p3date14_query);*/
    $p3date14_a =0;
    $p3date14 = $p3date14_a[0];
    $p3date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 26 and 30");
    $p3date14Count_a = mysql_fetch_array($p3date14Count_query);
    $p3date14Count = $p3date14Count_a[0];
    /*$p3date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 31 and 40) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date15_a = mysql_fetch_array($p3date15_query);*/
    $p3date15_a =0;
    $p3date15 = $p3date15_a[0];
    $p3date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 31 and 40");
    $p3date15Count_a = mysql_fetch_array($p3date15Count_query);
    $p3date15Count = $p3date15Count_a[0];
    /*$p3date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 41 and 50) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date16_a = mysql_fetch_array($p3date16_query);*/
    $p3date16_a =0;
    $p3date16 = $p3date16_a[0];
    $p3date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 41 and 50");
    $p3date16Count_a = mysql_fetch_array($p3date16Count_query);
    $p3date16Count = $p3date16Count_a[0];
    /*$p3date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 51 and 60) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date17_a = mysql_fetch_array($p3date17_query);*/
    $p3date17_a = 0;
    $p3date17 = $p3date17_a[0];
    $p3date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 51 and 60");
    $p3date17Count_a = mysql_fetch_array($p3date17Count_query);
    $p3date17Count = $p3date17Count_a[0];
    /*$p3date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 61 and 70) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date18_a = mysql_fetch_array($p3date18_query);*/
    $p3date18_a =0;
    $p3date18 = $p3date18_a[0];
    $p3date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 61 and 70");
    $p3date18Count_a = mysql_fetch_array($p3date18Count_query);
    $p3date18Count = $p3date18Count_a[0];
    /*$p3date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 71 and 80) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date19_a = mysql_fetch_array($p3date19_query);*/
    $p3date19_a =0;
    $p3date19 = $p3date19_a[0];
    $p3date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 71 and 80");
    $p3date19Count_a = mysql_fetch_array($p3date19Count_query);
    $p3date19Count = $p3date19Count_a[0];
    /*$p3date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 81 and 90) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date20_a = mysql_fetch_array($p3date20_query);*/
    $p3date20_a =0;
    $p3date20 = $p3date20_a[0];
    $p3date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 81 and 90");
    $p3date20Count_a = mysql_fetch_array($p3date20Count_query);
    $p3date20Count = $p3date20Count_a[0];
    /*$p3date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level  between 91 and 100) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p3date21_a = mysql_fetch_array($p3date21_query);*/
    $p3date21_a =0;
    $p3date21 = $p3date21_a[0];
    $p3date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_2_level between 91 and 100");
    $p3date21Count_a = mysql_fetch_array($p3date21Count_query);
    $p3date21Count = $p3date21Count_a[0];

    $heroData_2_level = array(json_encode($p3date));
    // p4等级分布
    $p4date = array('1' => array($p4date1Count, $p4date1), array($p4date2Count, $p4date2), array($p4date3Count, $p4date3), array($p4date4Count, $p4date4), array($p4date5Count, $p4date5), array($p4date6Count, $p4date6), array($p4date7Count, $p4date7), array($p4date8Count, $p4date8), array($p4date9Count, $p4date9), array($p4date10Count, $p4date10), array($p4date11Count, $p4date11), array($p4date12Count, $p4date12), array($p4date13Count, $p4date13), array($p4date14Count, $p4date14), array($p4date15Count, $p4date15), array($p4date16Count, $p4date16), array($p4date17Count, $p4date17), array($p4date18Count, $p4date18), array($p4date19Count, $p4date19), array($p4date20Count, $p4date20), array($p4date21Count, $p4date21));
    // $date1[] = 
    /*$p4date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 1) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date1_a = mysql_fetch_array($p4date1_query);*/
    $p4date1_a =0;
    $p4date1 = $p4date1_a[0];
    $p4date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 1");
    $p4date1Count_a = mysql_fetch_array($p4date1Count_query);
    $p4date1Count = $p4date1Count_a[0];

    /*$p4date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 2) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date2_a = mysql_fetch_array($p4date2_query);*/
    $p4date2_a =0;
    $p4date2 = $p4date2_a[0];
    $p4date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 2");
    $p4date2Count_a = mysql_fetch_array($p4date2Count_query);
    $p4date2Count = $p4date2Count_a[0];
    /*$p4date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 3) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date3_a = mysql_fetch_array($p4date3_query);*/
    $p4date3_a =0;
    $p4date3 = $p4date3_a[0];
    $p4date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 3");
    $p4date3Count_a = mysql_fetch_array($p4date3Count_query);
    $p4date3Count = $p4date3Count_a[0];
    /*$p4date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 4) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date4_a = mysql_fetch_array($p4date4_query);*/
    $p4date4_a =0;
    $p4date4 = $p4date4_a[0];
    $p4date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 4");
    $p4date4Count_a = mysql_fetch_array($p4date4Count_query);
    $p4date4Count = $p4date4Count_a[0];
    /*$p4date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 5) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date5_a = mysql_fetch_array($p4date5_query);*/
    $p4date5_a =0;
    $p4date5 = $p4date5_a[0];
    $p4date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 5");
    $p4date5Count_a = mysql_fetch_array($p4date5Count_query);
    $p4date5Count = $p4date5Count_a[0];
    /*$p4date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 6) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date6_a = mysql_fetch_array($p4date6_query);*/
    $p4date6_a =0;
    $p4date6 = $p4date6_a[0];
    $p4date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 6");
    $p4date6Count_a = mysql_fetch_array($p4date6Count_query);
    $p4date6Count = $p4date6Count_a[0];
    /*$p4date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 7) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date7_a = mysql_fetch_array($p4date7_query);*/
    $p4date7_a =0;
    $p4date7 = $p4date7_a[0];
    $p4date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 7");
    $p4date7Count_a = mysql_fetch_array($p4date7Count_query);
    $p4date7Count = $p4date7Count_a[0];
    /*$p4date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 8) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date8_a = mysql_fetch_array($p4date8_query);*/
    $p4date8_a =0;
    $p4date8 = $p4date8_a[0];
    $p4date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 8");
    $p4date8Count_a = mysql_fetch_array($p4date8Count_query);
    $p4date8Count = $p4date8Count_a[0];
    /*$p4date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 9) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date9_a = mysql_fetch_array($p4date9_query);*/
    $p4date9_a =0;
    $p4date9 = $p4date9_a[0];
    $p4date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 9");
    $p4date9Count_a = mysql_fetch_array($p4date9Count_query);
    $p4date9Count = $p4date9Count_a[0];
    /*$p4date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  = 10) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date10_a = mysql_fetch_array($p4date10_query);*/
    $p4date10_a =0;
    $p4date10 = $p4date10_a[0];
    $p4date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level = 10");
    $p4date10Count_a = mysql_fetch_array($p4date10Count_query);
    $p4date10Count = $p4date10Count_a[0];
    /*$p4date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 11 and 15) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date11_a = mysql_fetch_array($p4date11_query);*/
    $p4date11_a = 0;
    $p4date11 = $p4date11_a[0];
    $p4date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 11 and 15");
    $p4date11Count_a = mysql_fetch_array($p4date11Count_query);
    $p4date11Count = $p4date11Count_a[0];
    /*$p4date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 16 and 20) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date12_a = mysql_fetch_array($p4date12_query);*/
    $p4date12_a =0;
    $p4date12 = $p4date12_a[0];
    $p4date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 16 and 20");
    $p4date12Count_a = mysql_fetch_array($p4date12Count_query);
    $p4date12Count = $p4date12Count_a[0];
    /*$p4date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 21 and 25) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date13_a = mysql_fetch_array($p4date13_query);*/
    $p4date13_a =0;
    $p4date13 = $p4date13_a[0];
    $p4date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 21 and 25");
    $p4date13Count_a = mysql_fetch_array($p4date13Count_query);
    $p4date13Count = $p4date13Count_a[0];
    /*$p4date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 26 and 30) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date14_a = mysql_fetch_array($p4date14_query);*/
    $p4date14_a = 0;
    $p4date14 = $p4date14_a[0];
    $p4date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 26 and 30");
    $p4date14Count_a = mysql_fetch_array($p4date14Count_query);
    $p4date14Count = $p4date14Count_a[0];
    /*$p4date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 31 and 40) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date15_a = mysql_fetch_array($p4date15_query);*/
    $p4date15_a =0;
    $p4date15 = $p4date15_a[0];
    $p4date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 31 and 40");
    $p4date15Count_a = mysql_fetch_array($p4date15Count_query);
    $p4date15Count = $p4date15Count_a[0];
    /*$p4date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 41 and 50) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date16_a = mysql_fetch_array($p4date16_query);*/
    $p4date16_a =0;
    $p4date16 = $p4date16_a[0];
    $p4date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 41 and 50");
    $p4date16Count_a = mysql_fetch_array($p4date16Count_query);
    $p4date16Count = $p4date16Count_a[0];
    /*$p4date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 51 and 60) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date17_a = mysql_fetch_array($p4date17_query);*/
    $p4date17_a =0;
    $p4date17 = $p4date17_a[0];
    $p4date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 51 and 60");
    $p4date17Count_a = mysql_fetch_array($p4date17Count_query);
    $p4date17Count = $p4date17Count_a[0];
    /*$p4date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 61 and 70) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date18_a = mysql_fetch_array($p4date18_query);*/
    $p4date18_a =0;
    $p4date18 = $p4date18_a[0];
    $p4date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 61 and 70");
    $p4date18Count_a = mysql_fetch_array($p4date18Count_query);
    $p4date18Count = $p4date18Count_a[0];
    /*$p4date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 71 and 80) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date19_a = mysql_fetch_array($p4date19_query);*/
    $p4date19_a =0;
    $p4date19 = $p4date19_a[0];
    $p4date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 71 and 80");
    $p4date19Count_a = mysql_fetch_array($p4date19Count_query);
    $p4date19Count = $p4date19Count_a[0];
    /*$p4date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 81 and 90) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date20_a = mysql_fetch_array($p4date20_query);*/
    $p4date20_a =0;
    $p4date20 = $p4date20_a[0];
    $p4date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 81 and 90");
    $p4date20Count_a = mysql_fetch_array($p4date20Count_query);
    $p4date20Count = $p4date20Count_a[0];
    /*$p4date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level  between 91 and 100) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p4date21_a = mysql_fetch_array($p4date21_query);*/
    $p4date21_a =0;
    $p4date21 = $p4date21_a[0];
    $p4date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_3_level between 91 and 100");
    $p4date21Count_a = mysql_fetch_array($p4date21Count_query);
    $p4date21Count = $p4date21Count_a[0];
    $heroData_3_level = array(json_encode($p4date));
    // p5等级分布(人数,所占百分比)
    $p5date = array('1' => array($p5date1Count, $p5date1), array($p5date2Count, $p5date2), array($p5date3Count, $p5date3), array($p5date4Count, $p5date4), array($p5date5Count, $p5date5), array($p5date6Count, $p5date6), array($p5date7Count, $p5date7), array($p5date8Count, $p5date8), array($p5date9Count, $p5date9), array($p5date10Count, $p5date10), array($p5date11Count, $p5date11), array($p5date12Count, $p5date12), array($p5date13Count, $p5date13), array($p5date14Count, $p5date14), array($p5date15Count, $p5date15), array($p5date16Count, $p5date16), array($p5date17Count, $p5date17), array($p5date18Count, $p5date18), array($p5date19Count, $p5date19), array($p5date20Count, $p5date20), array($p5date21Count, $p5date21));
    // $date1[] = 
    /*$p5date1_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 1) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date1_a = mysql_fetch_array($p5date1_query);*/
    $p5date1_a =0;
    $p5date1 = $p5date1_a[0];

    $p5date1Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 1");
    $p5date1Count_a = mysql_fetch_array($p5date1Count_query);
    $p5date1Count = $p5date1Count_a[0];
    // $date1 = $date1_a[0]
    /*$p5date2_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 2) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date2_a = mysql_fetch_array($p5date2_query);*/
    $p5date2_a =0;
    $p5date2 = $p5date2_a[0];
    $p5date2Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 2");
    $p5date2Count_a = mysql_fetch_array($p5date2Count_query);
    $p5date2Count = $p5date2Count_a[0];

    /*$p5date3_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 3) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date3_a = mysql_fetch_array($p5date3_query);*/
    $p5date3_a =0;
    $p5date3 = $p5date3_a[0];
    $p5date3Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 3");
    $p5date3Count_a = mysql_fetch_array($p5date3Count_query);
    $p5date3Count = $p5date3Count_a[0];

    /*$p5date4_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 4) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date4_a = mysql_fetch_array($p5date4_query);*/
    $p5date4_a =0;
    $p5date4 = $p5date4_a[0];
    $p5date4Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 4");
    $p5date4Count_a = mysql_fetch_array($p5date4Count_query);
    $p5date4Count = $p5date4Count_a[0];
    /*$p5date5_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 5) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date5_a = mysql_fetch_array($p5date5_query);*/
    $p5date5_a =0;
    $p5date5 = $p5date5_a[0];
    $p5date5Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 5");
    $p5date5Count_a = mysql_fetch_array($p5date5Count_query);
    $p5date5Count = $p5date5Count_a[0];
    /*$p5date6_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 6) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date6_a = mysql_fetch_array($p5date6_query);*/
    $p5date6_a =0;
    $p5date6 = $p5date6_a[0];
    $p5date6Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 6");
    $p5date6Count_a = mysql_fetch_array($p5date6Count_query);
    $p5date6Count = $p5date6Count_a[0];
    /*$p5date7_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 7) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date7_a = mysql_fetch_array($p5date7_query);*/
    $p5date7_a =0;
    $p5date7 = $p5date7_a[0];
    $p5date7Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 7");
    $p5date7Count_a = mysql_fetch_array($p5date7Count_query);
    $p5date7Count = $p5date7Count_a[0];
    /*$p5date8_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 8) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date8_a = mysql_fetch_array($p5date8_query);*/
    $p5date8_a =0;
    $p5date8 = $p5date8_a[0];
    $p5date8Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 8");
    $p5date8Count_a = mysql_fetch_array($p5date8Count_query);
    $p5date8Count = $p5date8Count_a[0];
    /*$p5date9_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 9) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date9_a = mysql_fetch_array($p5date9_query);*/
    $p5date9_a =0;
    $p5date9 = $p5date9_a[0];
    $p5date9Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 9");
    $p5date9Count_a = mysql_fetch_array($p5date9Count_query);
    $p5date9Count = $p5date9Count_a[0];
    /*$p5date10_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  = 10) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date10_a = mysql_fetch_array($p5date10_query);*/
    $p5date10_a =0;
    $p5date10 = $p5date10_a[0];
    $p5date10Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level = 10");
    $p5date10Count_a = mysql_fetch_array($p5date10Count_query);
    $p5date10Count = $p5date10Count_a[0];
    /*$p5date11_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 11 and  15) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date11_a = mysql_fetch_array($p5date11_query);*/
    $p5date11_a =0;
    $p5date11 = $p5date11_a[0];
    $p5date11Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 11 and 15");
    $p5date11Count_a = mysql_fetch_array($p5date11Count_query);
    $p5date11Count = $p5date11Count_a[0];
    /*$p5date12_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 16 and  20) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date12_a = mysql_fetch_array($p5date12_query);*/
    $p5date12_a =0;
    $p5date12 = $p5date12_a[0];
    $p5date12Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 16 and 20");
    $p5date12Count_a = mysql_fetch_array($p5date12Count_query);
    $p5date12Count = $p5date12Count_a[0];
    /*$p5date13_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 21 and  25) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date13_a = mysql_fetch_array($p5date13_query);*/
    $p5date13_a =0;
    $p5date13 = $p5date13_a[0];
    $p5date13Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 21 and 25 ");
    $p5date13Count_a = mysql_fetch_array($p5date13Count_query);
    $p5date13Count = $p5date13Count_a[0];
    /*$p5date14_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 26 and  30) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date14_a = mysql_fetch_array($p5date14_query);*/
    $p5date14_a =0;
    $p5date14 = $p5date14_a[0];
    $p5date14Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 26 and 30 ");
    $p5date14Count_a = mysql_fetch_array($p5date14Count_query);
    $p5date14Count = $p5date14Count_a[0];
    /*$p5date15_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 31 and  40) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date15_a = mysql_fetch_array($p5date15_query);*/
    $p5date15_a =0;
    $p5date15 = $p5date15_a[0];
    $p5date15Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 31 and 40");
    $p5date15Count_a = mysql_fetch_array($p5date15Count_query);
    $p5date15Count = $p5date15Count_a[0];
    /*$p5date16_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 41 and  50) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date16_a = mysql_fetch_array($p5date16_query);*/
    $p5date16_a =0;
    $p5date16 = $p5date16_a[0];
    $p5date16Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 41 and 50");
    $p5date16Count_a = mysql_fetch_array($p5date16Count_query);
    $p5date16Count = $p5date16Count_a[0];
    /*$p5date17_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 51 and  60) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date17_a = mysql_fetch_array($p5date17_query);*/
    $p5date17_a =0;
    $p5date17 = $p5date17_a[0];
    $p5date17Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 51 and 60");
    $p5date17Count_a = mysql_fetch_array($p5date17Count_query);
    $p5date17Count = $p5date17Count_a[0];
    /*$p5date18_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 61 and  70) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date18_a = mysql_fetch_array($p5date18_query);*/
    $p5date18_a =0;
    $p5date18 = $p5date18_a[0];
   // $p5date18Count_query = mysql_query("SELECT count(heroData_4_level)  FROM  hero  where heroData_4_level  between 61 and 70  and date ='$everylogdate[date]'");
    //$p5date18Count_a = mysql_fetch_array($p5date18Count_query);

    $p5date18Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 61 and 70");
    $p5date18Count_a = mysql_fetch_array($p5date18Count_query);
    $p5date18Count = $p5date18Count_a[0];
    /*$p5date19_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 71 and  80) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date19_a = mysql_fetch_array($p5date19_query);*/
    $p5date19_a =0;
    $p5date19 = $p5date19_a[0];
    $p5date19Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 71 and 80");
    $p5date19Count_a = mysql_fetch_array($p5date19Count_query);
    $p5date19Count = $p5date19Count_a[0];
    /*$p5date20_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 81 and  90) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date20_a = mysql_fetch_array($p5date20_query);*/
    $p5date20_a =0;
    $p5date20 = $p5date20_a[0];
    $p5date20Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 81 and 90");
    $p5date20Count_a = mysql_fetch_array($p5date20Count_query);
    $p5date20Count = $p5date20Count_a[0];
   /*$p5date21_query = mysql_query("SELECT concat( (
        (
        SELECT count( DISTINCT deviceid )
        FROM hero 
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level  between 91 and  100) / (
        SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]' )
        ) *100, '%')");
    $p5date21_a = mysql_fetch_array($p5date21_query);*/
    $p5date21_a =0;
    $p5date21 = $p5date21_a[0];
    $p5date21Count_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'
        AND heroData_4_level between 91 and 100");
    $p5date21Count_a = mysql_fetch_array($p5date21Count_query);
    $p5date21Count = $p5date21Count_a[0];

    $heroData_4_level = array(json_encode($p5date));

    //今日付费次数 paytimes
    $paytimes_query = mysql_query("SELECT sum(cents099 + Cents1999 + Cents499 + Cents4999 + Cents9999)  FROM  hero  where  date ='$everylogdate[date]'");
    $paytimes = mysql_fetch_array($paytimes_query);
    //今日付费用户数 PayPesonrNum
    $PayPesonrNum_query = mysql_query("SELECT  DISTINCT deviceid FROM `hero` WHERE cents099 >0  and date = '$everylogdate[date]'   union 
        SELECT  DISTINCT deviceid FROM `hero` WHERE  Cents1999 >0 and date = '$everylogdate[date]'  union
        SELECT  DISTINCT deviceid FROM `hero` WHERE  Cents499 >0  and date = '$everylogdate[date]'   union
        SELECT  DISTINCT deviceid FROM `hero` WHERE  Cents4999 >0 and date = '$everylogdate[date]'  union
        SELECT  DISTINCT deviceid FROM `hero` WHERE  Cents9999 >0 and date = '$everylogdate[date]'  
        ");
    $PayPesonrNum = mysql_num_rows($PayPesonrNum_query);

      $iap1_query = mysql_query(" SELECT sum(cents099) FROM  hero  where  date ='$everylogdate[date]'  ");
    $iap1 = mysql_fetch_array($iap1_query);
   /* }
      var_dump($iap1_to[0]);*/
    //iap2
    $iap2_query = mysql_query("SELECT sum(Cents1999) FROM  hero where  date ='$everylogdate[date]' ");
    $iap2 = mysql_fetch_array($iap2_query);
    //iap3
    $iap3_query = mysql_query("SELECT sum(Cents499) FROM  hero  where  date ='$everylogdate[date]' ");
    $iap3 = mysql_fetch_array($iap3_query);
    //iap4
    $iap4_query = mysql_query("SELECT sum(Cents4999) FROM  hero  where  date ='$everylogdate[date]' ");
    $iap4 = mysql_fetch_array($iap4_query);
    //iap5
    $iap5_query = mysql_query("SELECT sum(Cents9999) FROM  hero  where  date ='$everylogdate[date]' ");
    $iap5 = mysql_fetch_array($iap5_query);

     //newPayPesonrNum  新增付费人数
    $newPayPesonrNum_query = mysql_query("SELECT DISTINCT a.deviceid
        FROM (

        SELECT DISTINCT a.deviceid
        FROM hero a
        WHERE a.IAPMoney >0
        AND a.date = DATE_SUB(  '$everylogdate[date]', INTERVAL 0 
        DAY )
        )a
        LEFT JOIN (

        SELECT DISTINCT deviceid
        FROM hero
        WHERE DATE
        BETWEEN DATE_SUB(  '$everylogdate[date]', INTERVAL 360 
        DAY ) 
        AND DATE_SUB(  '$everylogdate[date]', INTERVAL 1 
        DAY ) 
        AND IAPMoney =0
        )b ON a.deviceid = b.deviceid
        WHERE b.deviceid IS NOT NULL");
    $newPayPesonrNum = mysql_num_rows($newPayPesonrNum_query);


     //WeekNewPayPesonrNum 过去7日内新增注册用户数
     $WeekNewPayPesonrNum_query = mysql_query("SELECT count( DISTINCT deviceid )
        FROM hero
        WHERE registerDate
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'");
     $WeekNewPayPesonrNum = mysql_fetch_array($WeekNewPayPesonrNum_query);
     //MonthLandTwicePesonrNum 过去30日内2次登录用户数
        $MonthLandTwicePesonrNum_query = mysql_query("SELECT DISTINCT deviceid, date
        FROM hero
        WHERE  date
        BETWEEN DATE_SUB( '$everylogdate[date]', INTERVAL 30
        DAY )
        AND DATE_SUB( '$everylogdate[date]', INTERVAL 1
        DAY )
        GROUP BY deviceid
        HAVING count( 1 ) >1 ");
     $MonthLandTwicePesonrNum = mysql_num_rows($MonthLandTwicePesonrNum_query);
     //WeekPayRechargeNum 周付费用户充值笔数
             $WeekPayRechargeNum_query = mysql_query("SELECT sum( cents099 + Cents1999 + Cents499 + Cents4999 + Cents9999)
        FROM hero
        WHERE date
        BETWEEN date_sub( '$everylogdate[date]', INTERVAL 7
        DAY )
        AND '$everylogdate[date]'");
     $WeekPayRechargeNum = mysql_fetch_array($WeekPayRechargeNum_query);
   
 $sql="REPLACE INTO report_nojailbreak (logdate,loginPersonNum,activePesonrNum,activePesonrTime,totalDayTotalTime,
                                        totalDayGetMoney,totalDayRecharge,totalDayUsedMoney,dayLoginPersonNum,
                                        totalDayNewusers,dayActivePesonrNum,dayActivePesonrTime,weekActivePesonrNum,weekLoyalPesonrNum,weekCorePesonrNum,
                                        dayTotalTime,dayUsedMoney,weekPayPesonrNum,dayIAPGetMoney,
                                        avgDayMoney,dayNowMoney,weekPayPesonrTime,
                                        
                                        weekPayARPU,weekActiveARPU,weekLogARPU,weekWastageRate,weekPayRate,weekLogPayRate,weekPayWastageRate,
                                        totalDayGetIAPMoney,playerLevel,player2Level,player3Level,player4Level,player5Level,totalDayPlayTime,paytimes,PayPesonrNum,
                                        Lastloginscreen10Num,Lastloginscreen21Num,Lastloginscreen23Num,Lastloginscreen24Num,Lastloginscreen31Num,Lastloginscreen41Num,
                                        Lastloginscreen42Num,Lastloginscreen50Num,Lastloginscreen60Num,Lastloginscreen71Num,Lastloginscreen72Num,Lastloginscreen73Num,Lastloginscreen80Num,
                                        iap1,iap2,iap3,iap4,iap5,newPayPesonrNum, weekOneLandPesonrNum,WeekNewPayPesonrNum,MonthLandTwicePesonrNum,WeekPayRechargeNum,dayRechargeNum) 
                  VALUES('$everylogdate[date]','$loginPersonNum[0]','$activePesonrNum[0]','$activePesonrTime[0]','$totalDayTotalTime[0]',
                         '$totalDayGetMoney[0]','$totalDayRecharge[0]','$totalDayUsedMoney[0]','$dayLoginPersonNum[0]',
                         '$totalDayNewusers[0]','$dayActivePesonrNum[0]','$dayActivePesonrTime[0]','$weekActivePesonrNum','$weekLoyalPesonrNum','$weekCorePesonrNum',
                          '$dayTotalTime[0]','$dayUsedMoney[0]','$weekPayPesonrNum','$dayIAPGetMoney[0]',
                          '$avgDayMoney[0]','$dayNowMoney[0]','$weekPayPesonrTime[0]',
                        
                          '$weekPayARPU[0]','$weekActiveARPU[0]','$weekLogARPU[0]','$weekWastageRate[0]','$weekPayRate[0]','$weekLogPayRate[0]','$weekPayWastageRate[0]',
                          '$totalDayGetIAPMoney[0]','$heroData_0_level[0]','$heroData_1_level[0]','$heroData_2_level[0]','$heroData_3_level[0]','$heroData_4_level[0]','$totalDailyLoginTimes[0]','$paytimes[0]','$PayPesonrNum',
                          '$Lastloginscreen10Num[0]','$Lastloginscreen21Num[0]','$Lastloginscreen23Num[0]','$Lastloginscreen24Num[0]',
                          '$Lastloginscreen31Num[0]','$Lastloginscreen41Num[0]','$Lastloginscreen42Num[0]','$Lastloginscreen50Num[0]',
                          '$Lastloginscreen60Num[0]','$Lastloginscreen71Num[0]','$Lastloginscreen72Num[0]','$Lastloginscreen73Num[0]','$Lastloginscreen80Num[0]',
                          '$iap1[0]','$iap2[0]','$iap3[0]','$iap4[0]','$iap5[0]','$newPayPesonrNum','$weekOneLandPesonrNum','$WeekNewPayPesonrNum[0]','$MonthLandTwicePesonrNum','$WeekPayRechargeNum[0]','$dayRechargeNum[0]'
                          )";
$query= @mysql_query($sql,$connection) or die(mysql_error());  

}
?>
